package com.woniu.controller;

import com.woniu.entity.PageData;
import com.woniu.entity.Result;
import com.woniu.entity.dto.CommentDTO;
import com.woniu.entity.dto.ExperimentDTO;
import com.woniu.pojo.Comment;
import com.woniu.pojo.Experiment;
import com.woniu.service.IExperimentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaosong
 * @since 2023-04-03
 */
@RestController
@RequestMapping("/experiment")
public class ExperimentController extends BaseController{

     @Autowired
     private IExperimentService experimentService;

    //      分页查实验详情信息。
    @PostMapping("/Search/{currentPage}/{pageSize}")
    @ApiOperation("分页条件查询")
    public Result selectPageAll(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody(required = false) ExperimentDTO experimentDTO
    ){

        PageData pageData = experimentService.search(currentPage,pageSize,experimentDTO);
        return toDataResult(pageData);
    }

    //    按照id查询
    @GetMapping("/selectByid/{id}")
    @ApiOperation("ID查询实验详情表")
    public Result  selectById(@PathVariable Integer id){

        Experiment experiment =  experimentService.findByid(id);
        return toDataResult(experiment);
    }

    //    按照id删除
//    @GetMapping("/delete/{id}")
//    @ApiOperation("根据id删除")
//    public Result deleteByid(@PathVariable Integer id){
//        boolean flag = experimentService.removeById(id);
//
//        return toResult(flag);
//    }
    //    批量删除
    @PostMapping("/delete")
    @ApiOperation("批量删除")
    public  Result deletes(@RequestBody List<String> list){

        boolean b =experimentService.removeBatchByIds(list);

        return toResult(b);
    }

    //    新增
    @PostMapping("/save")
    @ApiOperation("新增")
    public Result save(@RequestBody Experiment experiment){
        boolean flag = experimentService.saveExperiment(experiment);
        return toDataResult(flag);
    }
    //    修改
    @PostMapping("/update")
    @ApiOperation("修改")
    public Result Update(@RequestBody Experiment experiment){
        Integer num  = experimentService.updateExperment(experiment);
        return toDataResult(num);
    }
}
